package Experiment;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

public class foodCar extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置服务器端以UTF-8编码进行输出
        resp.setCharacterEncoding("UTF-8");
        //设置浏览器以UTF-8编码进行接收,解决中文乱码问题
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter out = resp.getWriter();
        String sss = req.getParameter("num1");
        HttpSession hs = req.getSession();
        if (req.getParameter("b1") != null || req.getParameter("b2") != null || req.getParameter("b3") != null) {
            hs.setAttribute("s1", req.getParameter("b1"));
            hs.setAttribute("s2", req.getParameter("b2"));
            hs.setAttribute("s3", req.getParameter("b3"));
        }
        String str = "";
        if (hs.getAttribute("s1") != null || hs.getAttribute("s2") != null || hs.getAttribute("s2") != null) {
            //str = (String)hs.getAttribute("s1");
            String s1 = new String(req.getParameter("b1").getBytes("ISO-8859-1"), "UTF-8");
            out.println("这是水果:" + s1 + sss + "<br>");
            //str = (String)hs.getAttribute("s2");
            String s2 = new String(req.getParameter("b2").getBytes("ISO-8859-1"), "UTF-8");
            out.println("这是水果:" + s2 + "<br>");
            //str = (String)hs.getAttribute("s3");
            String s3 = new String(req.getParameter("b3").getBytes("ISO-8859-1"), "UTF-8");
            out.println("这是水果:" + s3 + "<br>");

        }
//        out.println("这是苹果的数量"+sss);
    }
}
